package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.contract.MainConfig;
import com.sanpu.kxe.business.main.contract.NickNameModifyContract;
import com.sanpu.kxe.business.main.presenter.NickNameModifyPresenter;
import com.sanpu.kxe.module.widget.EditTextWithDel;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Description：昵称修改
 * Created by 薛勇军 on 2018/7/10.
 */

public class NickNameModifyActivity extends BaseTitleActivity implements NickNameModifyContract.View {

    @Bind(R.id.name)
    EditTextWithDel vName;

    private NickNameModifyContract.Presenter mPresenter;

    private String nickName;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_modify_name;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("设置昵称");
        mPresenter = new NickNameModifyPresenter(this);
    }

    @Override
    protected void initData() {
        super.initData();
        try {
            nickName = getIntent().getStringExtra(MainConfig.INTENT_NICKNAME);
            if (!TextUtils.isEmpty(nickName)) {
                vName.setText(nickName);
                vName.setSelection(nickName.length());
            }
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        }
    }

    @OnClick({R.id.commit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.commit:
                mPresenter.onCommit(vName.getText().toString(), nickName);
                break;
        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(NickNameModifyContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
